<?php
	/**
	 * 获取其他玩家信息
	 */
    class OtherPlayerInfo extends APIBase {
		
		public $tag = "OtherPlayerInfo";
    	public $isLogin = true;
		
		public function before() {
			$this->initCacheRedis();
			$this->initMysql();
			return true;
		}
		public function logic() {
			$uid = $this->uid;
			if (!isset($this->param['uid']) || $this->param['uid'] == '') {
				$this->returnError(310, "uid must be needed");
		    }
			$otherUid = $this->param['uid'];
			$otheruserinfo = $this->data_redis->hMget('hu:'.$otherUid,array('name','sex','point','avater_url','accid'));
			$matchdata = $this->data_redis->hGetAll('hu:'.$otherUid.':match');
			if(!empty($matchdata)){
			    $totalgames = (int)$matchdata['win_count']+(int)$matchdata['lose_count'];
			    $highest_winning_streak = (int)$matchdata['highest_winning_streak'];
				$winning_streak = (int)$matchdata['winning_streak'];//连胜
				 if((int)$totalgames!=0){
				    $ratewinning = round((((int)$matchdata['win_count'] / (int)$totalgames) * 100)).'%';
			    }else{
				    $ratewinning = 0;
			    }
				if($winning_streak > $highest_winning_streak){
					$highest_winning_streak = $winning_streak;
				}
				$name = filter_emoji($otheruserinfo['name']);
			    $info = array('uid'=>$otherUid,'name'=>$name,'sex'=>$otheruserinfo['sex'],'avater_url'=>$otheruserinfo['avater_url'],'point'=>$otheruserinfo['point'],'accid'=>$otheruserinfo['accid'],
			    'totalgames'=>$totalgames,'highest_winning_streak'=>$highest_winning_streak,'ratewinning'=>$ratewinning);
                $this->returnData($info);
			}else{
				$this->returnError(301,'参数有误！');
			}			
		}
		
        public function after() {
			$this->deinitCacheRedis();
		}
    }
?>
